<template>
    <div class="view-container">
        <div class="">
            <h1>快速发布</h1>
            <div class="block" v-if="!isEdit" style="margin-bottom: 24px">
                <category-choose @get-params="getParams" :id="id"></category-choose>
            </div>
            <div style="margin-top: 224px ;display: block;text-align: center;" v-if="!isEdit">
                <el-button type="primary" size="large" @click="renderTemplate"  :disabled="canClick"
                           class="next">下一步
                </el-button>
            </div>

            <div class="productEdit" v-if="isEdit">
                <el-tabs type="card" v-model="editPro">
                    <el-tab-pane label="具体信息" name="info">
                        <!--第一个基本信息组件-->
                        <keep-alive>
                            <fast-pro-info :pro-category="proCategory" v-if="JSON.stringify(proCategory)!=='{}'">
                            </fast-pro-info>
                        </keep-alive>
                    </el-tab-pane>
                </el-tabs>
            </div>
        </div>
    </div>
</template>

<script>
    import fastProInfo from './tabcontent/fastproinfo.vue';
    import categoryChoose from './tabcontent/categoryChoose.vue';
    import {getStanderdTemplate} from '@/api/fastPublish';
    import {clearSession} from '@/utils/removeSession';

    export default {
        name: 'goodsPublishFast',
        components: {fastProInfo, categoryChoose},
        data() {
            return {
                options: [],
                isEdit: false,
                editPro: 'info',
                categoryIds: {},
                proCategory: {},
                id: 0,
            }
        },
        computed: {
            canClick() {
                if (JSON.stringify(this.categoryIds) != '{}') {
                    return false
                } else {
                    return true
                }
            }
        },
        methods: {
            getParams(value) {
                this.categoryIds = value;
            },
            renderTemplate() {
                clearSession();
//下一步
                if (JSON.stringify(this.categoryIds) == "{}") {
                    this.$message({
                        message: '您还没选择商品分类',
                        type: 'warning'
                    });
                    return;
                } else {
                    this.isEdit = true;
                    getStanderdTemplate(this.categoryIds)
                        .then((resp) => {
//                            console.log('这是要发送的数据' + resp.data);
                            this.proCategory = resp.data;
                        })
                        .catch((err) => {
//                            console.log(err);
                            this.isEdit = false;
                        })
                }

            }
        }
    }
</script>

<style lang="less">

</style>
